<!-- 
	消息通知 item 
-->
<template>
    <view class="message-item" @click="clickItem()">
        <view class="message-item-top">
            <view class="unread-message-dot" v-if="data.Amount > 0"></view>
            <text class="message-title">{{ data.TitleName }}</text>
            <text class="message-time">{{ getTimeText(data.AddTime) }}</text>
        </view>
        <view class="message-item-main">
            <text class="message-content">{{ data.MessageStr }}</text>
        </view>
        <view class="message-item-bottom">
            <text class="sn-text">{{ data.FirstMsg }}</text>
            <text class="price-text">{{ data.SecondMsg }}</text>
        </view>
    </view>
</template>
<script>
import { ReduceAlert } from "@/pages_supplier/service/api/supplier.js"
export default {
    props: {
        data: {
            type: Object,
            default: () => {},
        },
    },
    data() {
        return {}
    },
    mounted() {},
    methods: {
        //点击消息
        clickItem() {
            //提交消息已读settlementOrder
            this.setRead()
            //跳转到详情页
            this.goDetail()
        },
        //提交消息已读
        setRead() {
            let param = {
                id: this.data.ID,
            }
            let path = "?id=" + this.data.ID
            //接口
            ReduceAlert(param, path).then((res) => {
                if (res.State == 1) {
                    this.data.Amount = 0
                    this.$forceUpdate()
                }
            })
        },
        getTimeText(time) {
            if (time) {
                if (this.isToday(time)) {
                    return `今天 ${time.split(" ")[1]}`
                }
                return time
            }
            return ""
        },
        isToday(time) {
            let d = new Date(time).setHours(0, 0, 0, 0)
            let today = new Date().setHours(0, 0, 0, 0)
            return d == today
        },
        //跳转到详情页
        goDetail() {
            //采购模式
            // 1、待接收订单：1个（协同采购单/销售采购单/采购订单）待接收，请及时处理。跳转对应采购订单详情
            // 2、待发货订单：1个订单待发货，请及时处理。跳转对应采购订单详情
            // 3、待审核退单：1个退货单待审核，请及时处理。跳转对应退货单详情
            // 4、待确认收款账单：1笔收款待确认，请及时处理。跳转采购单详情
            // 5、待审核账单：1笔账单待审核，请及时处理。跳转退货单详情
            // 6、待付款账单：1笔账单待审核，请及时处理。跳转退货单详情
            // 7、报价审核已通过：您的报价审核已通过，商品“XXXX”，跳到报价表，搜索该商品
            // 8、报价审核已驳回：您的报价审核已驳回，商品“XXXX”，跳到报价表，搜索该商品

            //供应模式
            // 供货订单消息通知如下：（左侧标题）
            // 1、待发货订单：1个订单待发货，请及时处理。跳转对应供货订单详情 this.easyGoTo('/pages_supplier/packet/supplyOrder/index?tabIndex=1')
            // 2、待审核退单：1个退货单待审核，请及时处理。跳转对应退货单详情	this.easyGoTo('/pages_supplier/packet/returnOrder/detail?id=' + item.RelateId)
            // 3、待确认收款账单：1笔收款待确认，请及时处理。跳转结算单详情   this.easyGoTo('/pages_supplier/packet/account/detail?id='+item.RelateId)
            // 4、待审核账单：1笔账单待审核，请及时处理。跳转结算单详情
            // 5、待开票账单：1笔账单待开票，请及时处理，跳转结算单详情
            // 6、重新开票：1笔账单需重新开票，请及时处理，跳转结算单详情

            let item = this.data
            switch (item.RelateType) {
                case "buyOrder":
                    //采购订单详情
                    this.easyGoTo("/pages_supplier/packet/order/orderDetail?id=" + item.RelateId)
                    break
                case "exchangeOrder":
                    //退货单
                    this.easyGoTo("/pages_supplier/packet/returnOrder/detail?id=" + item.RelateId)
                    break
                case "settlementOrder":
                    //结算详情
                    this.easyGoTo("/pages_supplier/packet/accountBuy/detail?id=" + item.RelateId)
                    break
                case "offerSkuPrice":
                    //报价审核
                    this.easyGoTo("/pages_supplier/packet/quotation/examine?id=" + item.RelateId + "&from=1")
                    break
                case "SupplierOrder":
                    //供应待发货订单
                    this.easyGoTo("/pages_supplier/packet/supplyOrder/index?tabIndex=1")
                    break
                case "SupplierPeriod":
                    //供应结算单
                    this.easyGoTo("/pages_supplier/packet/account/detail?id=" + item.RelateId)
                    break
                default:
                    break
            }
        },
    },
}
</script>

<style lang="scss">
.message-item {
    padding: $app-page-padding;
    margin: $app-page-padding $app-page-padding 0;
    background: #ffffff;
    border-radius: 8rpx;

    .message-item-top {
        display: flex;
        flex-direction: row;
        align-items: center;
        margin-bottom: 20rpx;

        .unread-message-dot {
            width: 12rpx;
            height: 12rpx;
            background: #f1270c;
            border-radius: 50%;
            margin-right: 12rpx;
        }

        .message-title {
            font-weight: bold;
            font-size: $font-size-32;
            flex: 1;
        }

        .message-time {
            color: $app-color-text-tip;
            font-size: $font-size-24;
        }
    }

    .message-item-main {
        margin-bottom: 20rpx;
        .message-content {
            display: flex;
            font-size: $font-size-28;
            color: $app-color-text-main;
            line-height: 36rpx;
        }
    }

    .message-item-bottom {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        text {
            color: $app-color-text-desc;
        }
        .sn-text {
            font-size: $font-size-24;
        }
        .price-text {
            font-size: $font-size-24;
        }
    }
}
</style>
